 
						** VT analysing core 5 ***
 
	clear
	version 15.1
	set seed 1234
	cd  "/Users/rich/Dropbox/research/Rich & Ferran/EBA turnout/data/"
 
								*** VT LAG ***
	
 
	use "/Users/rich/Dropbox/research/Rich & Ferran/EBA turnout/data/completed data/completed AWS data files (cleaned)/core_vt_lag.dta"
	
	
	** dropping unnecessary variables **
		
			drop if _id==.
			drop title marginsok vce depvar cmd properties predict model ///
				estat_cmd vcetype clustvar 
			drop if vif1>7
		
		** 1.3. Mean of Coef, SE, min, max    **		 
			sum coef if var=="vt_lag"
		** 1.4.  %(significant != 0)  **
			count if var=="vt_lag" &   pval<=.05 & pval~=.	 	
		** 1.5. %(beta < 0)  		 
			count if var=="vt_lag" & coef<0 & coef~=.
		** 1.5. %(beta > 0)  		 
			count if var=="vt_lag" & coef>0 & coef~=.				
		** 1.6.  %(signif & beta <= 0)  				
			count if var=="vt_lag" &  	pval<=.05 &	coef<=0 		
		** 1.7.  %(signif & beta > 0)  				
			count if var=="vt_lag" &  	pval<=.05 &	coef>0 
		
		** Hegre and Sambanis weights calculation **	
		  
		drop llsum_all w_all beta_mean beta_w sd_w sd_mean t cdf cdf_w
			** generating weights 
			egen llsum_all= sum(ll)
			gen w_all=ll/llsum_all
			
			* beta *
			gen beta_w=coef*w_all if var=="vt_lag"
			egen beta_mean=sum(beta_w)		
			codebook beta_mean
			
			* sd *
			gen sd_w=stderr*w_all if var=="vt_lag"
			egen sd_mean=sum(sd_w)
			codebook sd_mean
			
			* Tstat  *
			gen t=beta_mean/sd_mean
			codebook  t
			
			** Pvalue  (ttail(DF, T)
			display ttail( 2433115, 9.4931993 ) 
			                     
 
		** Sala-i-Martin's Extreme Bounds Analysis (EBA):
		
		sort coef
 		cumul coef if var=="vt_lag", gen(cdf) equal
 		cumul beta_mean if var=="vt_lag", gen(cdf_w) equal
				
		sort beta_mean
		browse coef cdf cdf_w if cdf~=.	
 
		global graph_options ", freq  xline(0, lcolor(red)) ytitle("") xtitle("") normal gap(25) ylabel(, angle(0) labsize(small))"
		
 
		** In all models ***
		hist coef if var=="vt_lag" $graph_options title("Lagged DV, Coefficients") saving(h1c, replace)
		hist tstat if var=="vt_lag" $graph_options title("Lagged DV, T-stat") saving(h1t, replace)
		

								*** COMP ***
	
	clear
	use "/Users/rich/Dropbox/research/Rich & Ferran/EBA turnout/data/completed data/completed AWS data files (cleaned)/core_comp.dta"
	
	
	** dropping unnecessary variables **
		
			drop if _id==.
			drop title marginsok vce depvar cmd properties predict model ///
				estat_cmd vcetype clustvar 
			drop if vif1>7
		
		** 1.3. Mean of Coef, SE, min, max    **		 
			sum coef if var=="comp"
		** 1.4.  %(significant != 0)  **
			count if var=="comp" &   pval<=.05 & pval~=.	 	
		** 1.5. %(beta < 0)  		 
			count if var=="comp" & coef<0 & coef~=.
		** 1.5. %(beta > 0)  		 
			count if var=="comp" & coef>0 & coef~=.				
		** 1.6.  %(signif & beta <= 0)  				
			count if var=="comp" &  	pval<=.05 &	coef<=0 		
		** 1.7.  %(signif & beta > 0)  				
			count if var=="comp" &  	pval<=.05 &	coef>0 
		
		** Hegre and Sambanis weights calculation **	
		  
		drop llsum_all w_all beta_mean beta_w sd_w sd_mean t cdf cdf_w
			** generating weights 
			egen llsum_all= sum(ll)
			gen w_all=ll/llsum_all
			
			* beta *
			gen beta_w=coef*w_all if var=="comp"
			egen beta_mean=sum(beta_w)		
			codebook beta_mean
			
			* sd *
			gen sd_w=stderr*w_all if var=="comp"
			egen sd_mean=sum(sd_w)
			codebook sd_mean
			
			* Tstat  *
			gen t=beta_mean/sd_mean
			codebook  t
			
			** Pvalue  (ttail(DF, T)
			display ttail( 2432871, 2.2856367 ) 
			                     
 
		** Sala-i-Martin's Extreme Bounds Analysis (EBA):
		
		sort coef
 		cumul coef if var=="comp", gen(cdf) equal
 		cumul beta_mean if var=="comp", gen(cdf_w) equal
				
		sort beta_mean
		browse coef cdf cdf_w if cdf~=.	
 
		hist coef if var=="comp" $graph_options title("Compulsory voting, Coefficients") saving(h2c, replace)
		hist tstat if var=="comp" $graph_options title("Compulsory voting, T-statistic") saving(h2t, replace)
		

								*** PR ***
	clear
 
	use "/Users/rich/Dropbox/research/Rich & Ferran/EBA turnout/data/completed data/completed AWS data files (cleaned)/core_pr.dta"
	
	
	** dropping unnecessary variables **
		
			drop if _id==.
			drop title marginsok vce depvar cmd properties predict model ///
				estat_cmd vcetype clustvar 
			drop if vif1>7
		
		** 1.3. Mean of Coef, SE, min, max    **		 
			sum coef if var=="pr"
		** 1.4.  %(significant != 0)  **
			count if var=="pr" &   pval<=.05 & pval~=.	 	
		** 1.5. %(beta < 0)  		 
			count if var=="pr" & coef<0 & coef~=.
		** 1.5. %(beta > 0)  		 
			count if var=="pr" & coef>0 & coef~=.				
		** 1.6.  %(signif & beta <= 0)  				
			count if var=="pr" &  	pval<=.05 &	coef<=0 		
		** 1.7.  %(signif & beta > 0)  				
			count if var=="pr" &  	pval<=.05 &	coef>0 
		
		** Hegre and Sambanis weights calculation **	
		  
		drop llsum_all w_all beta_mean beta_w sd_w sd_mean t cdf cdf_w
			** generating weights 
			egen llsum_all= sum(ll)
			gen w_all=ll/llsum_all
			
			* beta *
			gen beta_w=coef*w_all if var=="pr"
			egen beta_mean=sum(beta_w)		
			codebook beta_mean
			
			* sd *
			gen sd_w=stderr*w_all if var=="pr"
			egen sd_mean=sum(sd_w)
			codebook sd_mean
			
			* Tstat  *
			gen t=beta_mean/sd_mean
			codebook  t
			
			** Pvalue  (ttail(DF, T)
			display ttail(2432249,.91456741) 
			                     
 
		** Sala-i-Martin's Extreme Bounds Analysis (EBA):
		
		sort coef
 		cumul coef if var=="pr", gen(cdf) equal
 		cumul beta_mean if var=="pr", gen(cdf_w) equal
				
		sort beta_mean
		browse coef cdf cdf_w if cdf~=.	
 
		hist coef if var=="pr" $graph_options title("Proportional representation, Coefficients") saving(h3c, replace)
		hist tstat if var=="pr" $graph_options title("Proportional representation, T-statistic") saving(h3t, replace)
	
				

								*** GNI ***
	clear
	use "/Users/rich/Dropbox/research/Rich & Ferran/EBA turnout/data/completed data/completed AWS data files (cleaned)/core_gni_ln_sl.dta"
	
	
	** dropping unnecessary variables **
		
			drop if _id==.
			drop title marginsok vce depvar cmd properties predict model ///
				estat_cmd vcetype clustvar 
			drop if vif1>7
		
		** 1.3. Mean of Coef, SE, min, max    **		 
			sum coef if var=="gni_ln_sl"
		** 1.4.  %(significant != 0)  **
			count if var=="gni_ln_sl" &   pval<=.05 & pval~=.	 	
		** 1.5. %(beta < 0)  		 
			count if var=="gni_ln_sl" & coef<0 & coef~=.
		** 1.5. %(beta > 0)  		 
			count if var=="gni_ln_sl" & coef>0 & coef~=.				
		** 1.6.  %(signif & beta <= 0)  				
			count if var=="gni_ln_sl" &  	pval<=.05 &	coef<=0 		
		** 1.7.  %(signif & beta > 0)  				
			count if var=="gni_ln_sl" &  	pval<=.05 &	coef>0 
		
		** Hegre and Sambanis weights calculation **	
		  
		drop llsum_all w_all beta_mean beta_w sd_w sd_mean t cdf cdf_w
			** generating weights 
			egen llsum_all= sum(ll)
			gen w_all=ll/llsum_all
			
			* beta *
			gen beta_w=coef*w_all if var=="gni_ln_sl"
			egen beta_mean=sum(beta_w)		
			codebook beta_mean
			
			* sd *
			gen sd_w=stderr*w_all if var=="gni_ln_sl"
			egen sd_mean=sum(sd_w)
			codebook sd_mean
			
			* Tstat  *
			gen t=beta_mean/sd_mean
			codebook  t
			
			** Pvalue  (ttail(DF, T)
			display ttail(2432885 , .74889702 ) 
			                     
 
		** Sala-i-Martin's Extreme Bounds Analysis (EBA):
		
		sort coef
 		cumul coef if var=="gni_ln_sl", gen(cdf) equal
 		cumul beta_mean if var=="gni_ln_sl", gen(cdf_w) equal
				
		sort beta_mean
		browse coef cdf cdf_w if cdf~=.	
 
		hist coef if var=="gni_ln_sl" $graph_options title("GNI, Coefficients") saving(h4c, replace)
		hist coef if var=="gni_ln_sl" $graph_options title("GNI, T-statistics") saving(h4t, replace)
		

								*** POP ***
	clear
	use "/Users/rich/Dropbox/research/Rich & Ferran/EBA turnout/data/completed data/completed AWS data files (cleaned)/core_pop_ln_sl.dta"
	
	
	** dropping unnecessary variables **
		
			drop if _id==.
			drop title marginsok vce depvar cmd properties predict model ///
				estat_cmd vcetype clustvar 
			drop if vif1>7
		
		** 1.3. Mean of Coef, SE, min, max    **		 
			sum coef if var=="pop_ln_sl"
		** 1.4.  %(significant != 0)  **
			count if var=="pop_ln_sl" &   pval<=.05 & pval~=.	 	
		** 1.5. %(beta < 0)  		 
			count if var=="pop_ln_sl" & coef<0 & coef~=.
		** 1.5. %(beta > 0)  		 
			count if var=="pop_ln_sl" & coef>0 & coef~=.				
		** 1.6.  %(signif & beta <= 0)  				
			count if var=="pop_ln_sl" &  	pval<=.05 &	coef<=0 		
		** 1.7.  %(signif & beta > 0)  				
			count if var=="pop_ln_sl" &  	pval<=.05 &	coef>0 
		
		** Hegre and Sambanis weights calculation **	
		  
		drop llsum_all w_all beta_mean beta_w sd_w sd_mean t cdf cdf_w
			** generating weights 
			egen llsum_all= sum(ll)
			gen w_all=ll/llsum_all
			
			* beta *
			gen beta_w=coef*w_all if var=="pop_ln_sl"
			egen beta_mean=sum(beta_w)		
			codebook beta_mean
			
			* sd *
			gen sd_w=stderr*w_all if var=="pop_ln_sl"
			egen sd_mean=sum(sd_w)
			codebook sd_mean
			
			* Tstat  *
			gen t=beta_mean/sd_mean
			codebook  t
			
			** Pvalue  (ttail(DF, T)
			display ttail(2432887,-.51627314) 
			                     
 
		** Sala-i-Martin's Extreme Bounds Analysis (EBA):
		
		sort coef
 		cumul coef if var=="pop_ln_sl", gen(cdf) equal
 		cumul beta_mean if var=="pop_ln_sl", gen(cdf_w) equal
				
		sort beta_mean
		browse coef cdf cdf_w if cdf~=.	
 
		hist coef if var=="pop_ln_sl" $graph_options title("Population, Coefficients") saving(h5c, replace)
		hist coef if var=="pop_ln_sl" $graph_options title("Population, T-statistic") saving(h5t, replace)
		
		 graph combine h1c.gph h1t.gph h2c.gph h2t.gph h3c.gph h3t.gph h4c.gph ///
						h4t.gph h5c.gph h5t.gph , title("VT: Core 5")	///
						saving(VT_core.gph, replace)
	cd "/Users/rich/Dropbox/research/Rich & Ferran/EBA turnout/data/completed data/completed AWS data files (cleaned)/"			 
		erase  core_pop_ln_sl.dta
		erase  core_gni_ln_sl.dta
		erase core_vt_lag.dta 
		erase core_comp.dta
		erase  core_pr.dta
